Passed
Pull Request — master (#140)
by
unknown
03:53
created

Page   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 33
dl 0
loc 37
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A render 0 20 1
1
import React from 'react';
2
import PropTypes from 'prop-types';
3
import { connect } from 'react-redux';
4
import styled from 'styled-components';
5
import { push } from 'react-router-redux';
6
7
import BasicButton from 'components/elements/basic-button';
8
import { countActions } from 'controllers/actions/count';
9
import { messageActions } from 'controllers/actions/message';
10
11
export class Page extends React.PureComponent {
12
  static propTypes = {
13
    className: PropTypes.string,
14
    count: PropTypes.number,
15
    add: PropTypes.func,
16
    navigate: PropTypes.func,
17
    title: PropTypes.string,
18
    body: PropTypes.string,
19
    get: PropTypes.func,
20
  };
21
22
  static defaultProps = {
23
    count: 0,
24
    title: '',
25
    body: '',
26
  };
27
28
  render() {
29
    const { className, count, title, body } = this.props;
30
    const { add, get, navigate } = this.props;
31
    return (
32
      <div className={className}>
33
        <BasicButton
34
          className="statusButton"
35
          func={add}
36
          text={count.toString()}
37
        />
38
        <BasicButton className="actionButton" func={get} text="Get Message" />
39
        <BasicButton
40
          className="navButton"
41
          func={() => navigate('/second')}
42
          text="To Second Page"
43
        />
44
        <div className="title">{title}</div>
45
        <div className="body">{body}</div>
46
      </div>
47
    );
48
  }
49
}
50
51
const mapStateToProps = state => ({
52
  count: state.getIn(['count']),
53
  title: state.getIn(['message', 'data', 'title']),
54
  body: state.getIn(['message', 'data', 'body']),
55
});
56
57
const mapDispatchToProps = dispatch => ({
58
  add: () => dispatch(countActions.add()),
59
  navigate: location => dispatch(push(location)),
60
  get: () => dispatch(messageActions.get()),
61
});
62
63
const component = styled(Page)`
64
  width: 640px;
65
  margin: 240px auto;
66
  line-height: 30px;
67
68
  .statusButton {
69
    background: lightblue;
70
    color: white;
71
  }
72
73
  .actionButton {
74
    background: lightblue;
75
    color: white;
76
  }
77
`;
78
79
export default connect(
80
  mapStateToProps,
81
  mapDispatchToProps,
82
)(component);
83